home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / cp2dekit / samples / wavptype.cpp < prev    next >
C/C++ Source or Header  |  1996-12-29  |  2KB  |  81 lines

  1. //***************************************************************************
  2. //
  3. // this file is (c) '94-'96 Niklas Beisert
  4. //
  5. // this file is part of the cubic player development kit.
  6. // you may only use/modify/spread this file under the terms stated
  7. // in the cubic player development kit accompanying documentation.
  8. //
  9. //***************************************************************************
  10.  
  11.  
  12. // fileselector detection example
  13.  
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include "pfilesel.h"
  17. #include "binfile.h"
  18.  
  19. static unsigned char wavGetModuleType(const unsigned char *buf)
  20. {
  21.   if ((*(unsigned long*)buf==0x46464952)&&(*(unsigned long*)(buf+8)==0x45564157))
  22.     return mtWAV;
  23.  
  24.   return 0xFF;
  25. }
  26.  
  27.  
  28. static int wavReadMemInfo(moduleinfostruct &m, const unsigned char *buf, int len)
  29. {
  30.   int type=wavGetModuleType(buf);
  31.   m.modtype=type;
  32.   int i,j;
  33.  
  34.   switch (type)
  35.   {
  36.   case mtWAV:
  37.   {
  38.     i=20;
  39.     while (i<800)
  40.     {
  41.       if (*(unsigned long*)(buf+i-8)==0x20746D66)
  42.         break;
  43.       i+=8+*(unsigned long*)(buf+i-4);
  44.     }
  45.     if (i>=800)
  46.       return 1;
  47.  
  48.     char rate[10];
  49.     *m.modname=0;
  50.     ultoa(*(unsigned long*)(buf+i+4), rate, 10);
  51.     for (j=strlen(rate); j<5; j++)
  52.       strcat(m.modname, " ");
  53.     strcat(m.modname, rate);
  54.     if (*(unsigned short*)(buf+i+14)==8)
  55.       strcat(m.modname, "Hz,  8 bit, ");
  56.     else
  57.       strcat(m.modname, "Hz, 16 bit, ");
  58.     if (*(unsigned short*)(buf+i+2)==1)
  59.       strcat(m.modname, "mono");
  60.     else
  61.       strcat(m.modname, "stereo");
  62.     m.channels=*(unsigned short*)(buf+i+2);
  63.     if (*(unsigned long*)(buf+i+16)==61746164)
  64.       m.playtime=*(unsigned long*)(buf+i+20)/ *(unsigned long*)(buf+i+8);
  65.     return 1;
  66.   }
  67.   }
  68.   m.modtype=0xFF;
  69.   return 0;
  70. }
  71.  
  72. static int wavReadInfo(moduleinfostruct &m, binfile &f, const unsigned char *buf, int len)
  73. {
  74.   return 0;
  75. }
  76.  
  77. extern "C"
  78. {
  79.   mdbreadnforegstruct wavReadInfoReg = {wavReadMemInfo, wavReadInfo};
  80. };
  81.